﻿using LuShanTea.Service.Entities;
using System;
using System.Collections.Generic;
using System.Data.Entity.ModelConfiguration;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace LuShanTea.Service.ModelConfig
{
    class OrderConfig : EntityTypeConfiguration<Order>
    {
        public OrderConfig()
        {
            this.ToTable("T_Orders");

            this.HasRequired(o => o.User).WithMany().HasForeignKey(o => o.UserId).WillCascadeOnDelete(false);

            //this.HasRequired(o => o.Address).WithMany().HasForeignKey(o => o.AddressId).WillCascadeOnDelete(false);
            this.HasOptional(o => o.Address).WithMany().HasForeignKey(o => o.AddressId).WillCascadeOnDelete(false);

            this.HasRequired(o => o.Express).WithMany().HasForeignKey(o => o.ExpressId).WillCascadeOnDelete(false);

            this.HasRequired(o => o.Receipt).WithMany().HasForeignKey(o => o.ReceiptId).WillCascadeOnDelete(false);

            this.HasRequired(o => o.PayWay).WithMany().HasForeignKey(o => o.PayWayId).WillCascadeOnDelete(false);

            this.HasRequired(o => o.Status).WithMany().HasForeignKey(o => o.StatusId).WillCascadeOnDelete(false);


            Property(o => o.Amount).IsOptional();
            Property(o => o.Guid).IsRequired().HasMaxLength(256);
            Property(o => o.LeaveWord).HasMaxLength(64);
        }
    }
}
